package com.wngbms.netty._02http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.codec.http.HttpServerCodec;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class HttpServerInitializer extends ChannelInitializer<SocketChannel> {

    public HttpServerInitializer() {
        log.info("HttpServerInitializer init...");
    }

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();

//        pipeline.addLast("codec", new HttpServerCodec());
//        pipeline.addLast("handler", new HttpServerHandler());
        pipeline.addLast(new HttpRequestDecoder());
        pipeline.addLast(new HttpObjectAggregator(65535));
        pipeline.addLast(new HttpResponseEncoder());
        pipeline.addLast(new HttpEchoHandler());
        pipeline.addLast(new ServerExceptionHandler());
    }
}
